﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using UltimateMusicTagger;

namespace UltimateMp3TaggerUI
{
    partial class AboutBox : Form
    {
        const string LicenseFile = "gpl-2.0.txt";

        const string AuthorUrl = "http://www.codeplex.com/site/users/view/Zenon66";

        const string AuthorMail = "mailto:fabrizio.stellato@gmail.com";

        const string ProjectUrl = "http://umtagger.codeplex.com";

        const string DocumentationUrl = "http://umtagger.codeplex.com/documentation";

        public AboutBox()
        {
            InitializeComponent();
            this.Text = String.Format("About {0}", AssemblyTitle);
            this.labelProductName.Text = AssemblyProduct;
            //this.labelVersion.Text = String.Format("Version {0}", AssemblyVersion);
            this.labelVersion.Text = String.Format("Version {0}", MTUtility.GetVersion().ToString()); 
            this.labelCopyright.Text = AssemblyCopyright;
            this.linkLabelCompanyName.Text = AssemblyCompany;
            this.textBoxDescription.Text = AssemblyDescription;            
            //this.linkLabelHomepage.Text = Globals.HOME_PAGE;

            // attach handler
            this.linkLabelCompanyName.Click += (o, e) => { System.Diagnostics.Process.Start(AuthorMail); };
            this.linkLabelHomepage.Click += (o, e) => { System.Diagnostics.Process.Start(ProjectUrl); };
            this.linkLabelDocumentation.Click += (o, e) => { System.Diagnostics.Process.Start(DocumentationUrl); };

        }

        #region Assembly Attribute Accessors

        public string License
        {
            get
            {
                StringBuilder sb = new StringBuilder();

                if (File.Exists(LicenseFile))
                {
                    using (StreamReader sr = new StreamReader(LicenseFile))
                    {
                        String line = sr.ReadToEnd();
                        sb.Append(line);
                    }
                }
                else
                    sb.Append("http://www.gnu.org/licenses/gpl-2.0.txt");

                return sb.ToString();
            }
        }

        public string AssemblyTitle
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        public string AssemblyVersion
        {
            get
            {
                return Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }

        public string AssemblyDescription
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }

        public string AssemblyProduct
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }

        public string AssemblyCopyright
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        public string AssemblyCompany
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        #endregion

    }
}
